Jianshi = cc.Node.extend({
	ctor:function(p){
		this._super();
		p.addChild(this, 10, TAG_JIANSHI_NODE);
		this.loadjianshi();
		this.loadxiangjiao();
	},
	loadjianshi : function(){
		this.setCascadeOpacityEnabled(true);
		var jianshi= new Button(this, 10, TAG_JIANSHI, "#32.png",this.callback);		
	},
	loadxiangjiao : function(){
		this.setCascadeOpacityEnabled(true);
		var xiangjiao= new Button(this, 10, TAG_XIANGJIAO, "#dd/dc.png",this.callback);
		xiangjiao.setPosition(0,-175);
		
	},
	callback:function(p){
		var action = gg.flow.flow.action;
		var func = cc.callFunc(this.actionDone, this);	
		switch(p.getTag()){	
		case TAG_XIANGJIAO:
			if (action==X1){
				var paiqipao = new cc.Sprite("#paiqipao1.png");
				paiqipao.setPosition(-90,-100);
				paiqipao.setOpacity(0);
				paiqipao.setScale(0.5);
				this.addChild(paiqipao,1,TAG_PAIQI);
				var delay = cc.delayTime(1);
				var fadein = cc.fadeIn(0.5);
				var fade = cc.fadeTo(1.5,0);
				var seq1 = cc.sequence(fadein,delay,fade,cc.callFunc(function(){
					paiqipao.removeFromParent();
				},this));
				var delay1= cc.delayTime(2);
				var seq = cc.sequence(func,delay1,cc.callFunc(this.getParent().flowNext,this));
				p.runAction(seq);
				paiqipao.runAction(seq1);
			}
			else if (action==X2){
				var delay= cc.delayTime(2);
				var seq = cc.sequence(func,delay,cc.callFunc(this.getParent().flowNext,this));
				p.runAction(seq);
				}
			break;
		case TAG_JIANSHI:
			if (action==NONE){
				var move = cc.moveTo(1.5,cc.p(450,225));
				var delay = cc.delayTime(1);
				var delay1 = cc.delayTime(1.5);
				var rotate = cc.rotateTo(1,45);
				var rotate1=cc.rotateTo(1,0);

				var water = this.getParent().getChildByTag(TAG_WATER);
				var move1 = cc.moveTo(1.5,cc.p(636,300));
				var rotate2= cc.rotateTo(1.5,-60);
				var moveback=cc.moveTo(1.5,cc.p(750,430));
				var rotate3= cc.rotateTo(1.5,0);
				var spawn1 = cc.spawn(moveback,rotate3);
				var delay2 = cc.delayTime(4);
				var delay3 = cc.delayTime(0.5);
				var seq = cc.sequence(move,rotate,delay3,func,delay1,rotate1);
				this.runAction(seq);
				var seq2 = cc.sequence(cc.delayTime(3),func);
				p.runAction(seq2);
				var seq1 = cc.sequence(move1,rotate2,delay1,spawn1,cc.callFunc(function(){
					this.getParent().clock.doing();},this),delay2,cc.callFunc(function(){
						this.getParent().clock.stop();},this),
						cc.callFunc(this.getParent().flowNext,this));
				water.runAction(seq1);
		
			}
			else if (action==J1){
				var delay = cc.delayTime(2);
				var seq = cc.sequence(func,delay,cc.callFunc(this.getParent().flowNext,this));
				p.runAction(seq);
			}
			else if (action==J2){
				var move1 = cc.moveTo(1,cc.p(500,410));
				var movedown = cc.moveTo(0.5,cc.p(500,400));
				var delay = cc.delayTime(0.5);
				var seq= cc.sequence(move1,delay,movedown,delay);

				var iron = this.getParent().getChildByTag(TAG_IRON);
				var move = cc.moveTo(1.5,cc.p(520,280));
				var seq1 = cc.sequence(delay,move);

				var beakerflask = this.getParent().getChildByTag(TAG_BEAKERFLASK);
				var move2= cc.moveTo(1.5,cc.p(500,170));
				var seq2 = cc.sequence(delay,move2);
				
				
				var seq3 = cc.sequence(cc.delayTime(2),func,cc.callFunc(this.getParent().flowNext,this));
				p.runAction(seq3);
				iron.runAction(seq1);
				beakerflask.runAction(seq2);
				this.runAction(seq);
			}
			
			else if(action==J3){
				var delay = cc.delayTime(2);
				var seq = cc.sequence(func,delay,cc.callFunc(this.getParent().flowNext,this));
				p.runAction(seq);
				}
			else if(action==J4||action==J5){
				var close = this.getParent().getChildByTag(TAG_CLOSE);
				close.setVisible(true);
				var window = new cc.Sprite("#lite.png");
				window.setCascadeOpacityEnabled(true);
				window.setPosition(600,400);
				this.getParent().addChild(window,80,TAG_WINDOW);

				var fbeaker = new cc.Sprite("#fbeaker.png");
				fbeaker.setCascadeOpacityEnabled(true);
				fbeaker.setPosition(window.width*0.5,window.height*0.2);
				window.addChild(fbeaker,1,TAG_WFBEAKER);
				var fzi = new cc.LabelTTF.create("废液缸","微软雅黑","12");
				fzi.setPosition(fbeaker.width*0.5,fbeaker.height*0.3+23);
				fzi.setColor(cc.color(0, 0, 0, 0));
				fbeaker.addChild(fzi);

				var jianshinode = new cc.Sprite("#jianshinode.png");
				jianshinode.setCascadeOpacityEnabled(true);
				jianshinode.setPosition(window.width*0.5,window.height*0.6);
				window.addChild(jianshinode);
				
				var paishui = new cc.Sprite("#paishui.png");
			     paishui.setPosition(window.width*0.4-20,window.height*0.3);
			     paishui.setScale(0.8);
			     window.addChild(paishui);

				var label = new cc.LabelTTF("将清洗液倒入废液缸中","微软雅黑","30");
				label.setColor(cc.color(0,0,0,0));
				label.setPosition(window.width*0.2,20);
				window.addChild(label);

				var clyDtl = new cc.Sprite("#js.png");
				clyDtl.setPosition(jianshinode.width + clyDtl.width * 0.5,jianshinode.height * 0.5);
				clyDtl.setOpacity(0);
				clyDtl.setCascadeOpacityEnabled(true);
				jianshinode.addChild(clyDtl);
				var fade1 = cc.fadeIn(0.5);
				var delay = cc.delayTime(1.5);
				var fade2 = cc.fadeTo(0.5,0);
				var sequence = cc.sequence(fade1, delay, fade2);
				clyDtl.runAction(sequence);
				var clyLine = new cc.Sprite("#cly_line1.png");
				clyDtl.addChild(clyLine);
				clyLine.setPosition(clyDtl.width * 0.5, clyDtl.height * 0.4+5);
				var sequence = cc.sequence(cc.moveBy(1.5,cc.p(0,-clyDtl.height * 0.35)),cc.fadeTo(0.2,0));
				clyLine.runAction(sequence);	

				var delay = cc.delayTime(1.5);
				//var fade = cc.fadeTo(1,0);
//				var seq = cc.sequence(delay,fade,cc.callFunc(this.flowNext,this),cc.callFunc(function(){
//					window.removeFromParent();
//				},this));
				p.runAction(func);
				var seq = cc.sequence(cc.callFunc(this.flowNext,this));
				window.runAction(seq);		
				//var seq1 = cc.sequence(func);
				if (action==J5){
					this.getChildByTag(TAG_SHOW).removeFromParent();
					this.getParent().getChildByTag(TAG_IRON).runAction(cc.moveTo(1.5,cc.p(200,300)));
					this.runAction(cc.moveTo(1,cc.p(450,250)));
				}
				
				break;
			}
				
			break;
		}
	},
	
	actionDone:function(p){
		var action = gg.flow.flow.action;
		var func = cc.callFunc(this.actionDone, this);
		switch(p.getTag()){
		case TAG_XIANGJIAO:
		if (action==X1){
			var jianshi = this.getChildByTag(TAG_JIANSHI);
			var clyDtl = new cc.Sprite("#0ml.png");
			clyDtl.setPosition(jianshi.width + clyDtl.width * 0.5,0);
			clyDtl.setOpacity(0);
			this.addChild(clyDtl,1,TAG_SHOWRIGHT);
			var delay = cc.delayTime(1);
			var fadein = cc.fadeIn(0.5);
			var fade = cc.fadeTo(1.5,0);
			var seq = cc.sequence(fadein,delay,fade,cc.callFunc(function(){
				clyDtl.removeFromParent();
			},this));
			clyDtl.runAction(seq);
		
		}
		else if (action==X2){
			var jianshi = this.getChildByTag(TAG_JIANSHI);
			var zuoshou = new cc.Sprite("#zuoshou.png");
			zuoshou.setPosition(jianshi.width - zuoshou.width ,-150);
			zuoshou.setOpacity(0);
			this.addChild(zuoshou,1,TAG_SHOWLEFT);
			var delay = cc.delayTime(1);
			var fadein = cc.fadeIn(0.5);
			var fade = cc.fadeTo(1.5,0);
			var seq = cc.sequence(fadein,delay,fade,cc.callFunc(function(){
			zuoshou.removeFromParent();
			},this));
			zuoshou.runAction(seq);
			
			}
		break;
		case TAG_JIANSHI:
		if (action==NONE){		
			p.setCascadeOpacityEnabled(true);
			var clyDtl = new cc.Sprite("#js0.png");
			clyDtl.setPosition(p.width + clyDtl.width * 0.5,p.height * 0.2);
			clyDtl.setOpacity(0);
			clyDtl.setCascadeOpacityEnabled(true);
			this.addChild(clyDtl);
			var fade1 = cc.fadeTo(0.5, 255);
			var delay = cc.delayTime(1.5);
			var fade2 = cc.fadeTo(0.5,0);
			var sequence = cc.sequence(fade1, delay, fade2);
			clyDtl.runAction(sequence);
			var clyLine = new cc.Sprite("#cly_line1.png");
			clyDtl.addChild(clyLine);
			clyLine.setPosition(clyDtl.width * 0.5, 0);
			var seq = cc.sequence(cc.moveBy(1.5,cc.p(0,clyDtl.height * 0.8)),cc.callFunc(function(){
				clyLine.removeFromParent();
				clyDtl.removeFromParent();
			},this));
			clyLine.runAction(seq);		    					
		}
		else if(action==J1){			
			var clyDtl = new cc.Sprite("#js_1.png");
			clyDtl.setPosition(p.width + clyDtl.width * 0.5,0);
			clyDtl.setOpacity(0);
			this.addChild(clyDtl);
			var delay = cc.delayTime(1);
			var fadein = cc.fadeIn(1);
			var fade = cc.fadeTo(1.5,0);
			var seq = cc.sequence(fadein,delay,fade);
			clyDtl.runAction(seq);
		}
		else if (action==J2){
			var lanse = new cc.Sprite("#33.png");
			lanse.setPosition(p.width*0.5-5,p.height*0.5-185);
			lanse.setOpacity(0);
			this.addChild(lanse,12);
			var fadein = cc.fadeIn(0.5);
			lanse.runAction(fadein);
		
		}
		else if(action==J3){
			var jianshi = this.getChildByTag(TAG_JIANSHI);
			var clyDtl = new cc.Sprite("#25ml.png");
			clyDtl.setPosition(jianshi.width + clyDtl.width * 0.5,0);
			clyDtl.setOpacity(0);
			this.addChild(clyDtl);
			var delay = cc.delayTime(1);
			var fadein = cc.fadeIn(1);
			var fade = cc.fadeTo(1.5,0);
			var seq = cc.sequence(fadein,delay,fade);
			clyDtl.runAction(seq);		
			}
		else if(action==J4){
			var win = this.getParent().getChildByTag(TAG_WINDOW);
			var fbeaker = win.getChildByTag(TAG_WFBEAKER);
			var fbeaLine = new cc.Sprite("#beaker_line.png");
			fbeaker.addChild(fbeaLine);
			fbeaLine.setPosition(fbeaker.width * 0.5, fbeaLine.height * 0.5+5 );				
			var move1 = cc.moveBy(1,cc.p(0,fbeaker.height * 0.1));
	//		var delay = cc.delayTime(3);
//			var seq = cc.sequence(move1,delay,cc.callFunc(function(){
//				fbeaLine.removeFromParent();
//			},this));
		//	var seq = cc.sequence(move1);
			
			fbeaLine.runAction(move1);				
			break;	
			
		}
		break;
		}
	},
	flowNext:function(){

		gg.flow.next();
		cc.log("下一步"+gg.flow.flow.tag);
	}
});